# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=ois
pkgbase=mingw-w64-${_realname}-git
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}-git"
_base_ver=1.4.0
pkgver=1.4.0.50.6129c0a
pkgrel=1
provides=("${MINGW_PACKAGE_PREFIX}-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-${_realname}")
replaces=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgdesc="Object Oriented Input System (mingw-w64)"
arch=('any')
url="https://sourceforge.net/projects/wgois"
license=('custom:zlib/libpng')
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")
options=('strip' '!libtool' 'staticlibs')
makedepends=('autoconf' 'automake' 'libtool' "${MINGW_PACKAGE_PREFIX}-gcc" "git")
source=("${_realname}"::"git+https://github.com/wgois/OIS.git"
        0001-Upgrade-autotools-to-newer-version.-Allow-build-IOS-.patch
        0002-Fix-macros-name.patch
        0003-InputManager-Cannot-have-pure-virtual-methods.patch
        0004-Substitute-proper-OIS-libraries-in-config-files.-Fix.patch
        0005-Fix-typo.patch
        0006-Add-mingw-definitions-to-CFLAGS.patch
        0007-Fix-source-file-name.patch
        0008-Add-macros-directory-to-configure.patch
        0009-Switched-Win32Mouse-to-use-GetDeviceState-instead-of.patch
        0010-Unicode-fix.patch)
sha256sums=('SKIP'
            '9ac438aff02fd130ee1970dfd395dc008739c8dfd111c1a51f37412f07e71fe7'
            '2916602bee6851c4e44627cdde5ab48db58b6fbfc03971df440446d6c75c94c7'
            '3bd9cdb208c6ecd72060887dd4ff00f60c43067a02c0e3facecc890439a2ec73'
            '4f191559b8fe1d54d87864c86a5b3c8973abfd5e199b6728a2d821dea9bfd5df'
            '0146bf520e5b9cdd31bd6e327d20ea9d27d2782e3635fe8995b5ad41716b2eb0'
            '9ac1d5decbdf760464fbf8fb3a50570ebcc51cdfa54cf76fdb6d664b23adb352'
            '9a728cbd4dd8932d24cab17097cde6c6d8d6f9c3a79090dab697d14aacf53b74'
            '7980039e5e9151bc125f8e20a6ace6b0a849d2f4e6db88b642c6cca8ce524e9b'
            '5be6edebd934abd5a44d3111ac517806227a07591114a58ff4b64e4fefe6eb12'
            'b509b936232de332cf69f2c6204dc1d4a1bb7112872cc0dea9d69eda1ae449d7')

pkgver() {
  cd "${srcdir}/${_realname}"
  printf "%s.%s.%s" "${_base_ver}" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)"
}

prepare() {
  cd ${srcdir}/${_realname}
  git am --committer-date-is-author-date "${srcdir}"/0001-Upgrade-autotools-to-newer-version.-Allow-build-IOS-.patch
  git am --committer-date-is-author-date "${srcdir}"/0002-Fix-macros-name.patch
  git am --committer-date-is-author-date "${srcdir}"/0003-InputManager-Cannot-have-pure-virtual-methods.patch
  git am --committer-date-is-author-date "${srcdir}"/0004-Substitute-proper-OIS-libraries-in-config-files.-Fix.patch
  git am --committer-date-is-author-date "${srcdir}"/0005-Fix-typo.patch
  git am --committer-date-is-author-date "${srcdir}"/0006-Add-mingw-definitions-to-CFLAGS.patch
  git am --committer-date-is-author-date "${srcdir}"/0007-Fix-source-file-name.patch
  git am --committer-date-is-author-date "${srcdir}"/0008-Add-macros-directory-to-configure.patch
  git am --committer-date-is-author-date "${srcdir}"/0009-Switched-Win32Mouse-to-use-GetDeviceState-instead-of.patch
  git am --committer-date-is-author-date "${srcdir}"/0010-Unicode-fix.patch

  libtoolize --copy --force
  aclocal ${ACLOCAL_FLAGS}
  autoheader
  automake --include-deps --add-missing --foreign --copy
  autoconf
}

build() {
  [[ -d ${srcdir}/build-${MINGW_CHOST} ]] && rm -rf ${srcdir}/build-${MINGW_CHOST}
  mkdir -p ${srcdir}/build-${MINGW_CHOST} && cd ${srcdir}/build-${MINGW_CHOST}

  ../${_realname}/configure \
     --prefix=${MINGW_PREFIX} \
     --build=${MINGW_CHOST} \
     --host=${MINGW_CHOST} \
     --enable-shared=yes \
     --enable-static=yes

  make
}

package() {
  cd ${srcdir}/build-${MINGW_CHOST}
  make DESTDIR=${pkgdir} install
}
